#!/bin/bash

set_cgroup_rights()
{
	if [ -e /sys/fs/cgroup/cgroup.procs ]; then
		## cgroup v2
		echo "$PPID" > /sys/fs/cgroup/cgroup.procs
		echo "$$" > /sys/fs/cgroup/cgroup.procs
	else
		if [ -e /sys/fs/cgroup/cpuset/cgroup.procs ]; then
			## cgroup v1
			echo "$PPID" > /sys/fs/cgroup/cpuset/cgroup.procs 2>/dev/null
			echo "$$" > /sys/fs/cgroup/cpuset/cgroup.procs 2>/dev/null
		fi


		if [ -e /sys/fs/cgroup/memory/cgroup.procs ]; then
			## cgroup v1
			echo "$PPID" > /sys/fs/cgroup/memory/cgroup.procs 2>/dev/null
			echo "$$" > /sys/fs/cgroup/memory/cgroup.procs 2>/dev/null
		fi
	fi
}

export -f set_cgroup_rights
